package cn.edu.whu.lmars.dblgtree;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;

import com.vividsolutions.jts.geom.LineString;

//here enable the querying and handling of multliple DBLG-trees
//DBLG-tree can be referenced by other trees. 
//but only less significant feature will 
public class DBLGForest {
	
	private ArrayList<LTreeNode> trees = null;
	
	//how to initiate an start?
		//bulkload for a initialization
		//write this later.
	public static DBLGForest Init(LineString[] geoms) {
		DBLGForest dbf = new DBLGForest();
		dbf.trees = new ArrayList<LTreeNode>();
		
		Arrays.sort(geoms, new CoordsComp());
		
		int c = 0;
		ArrayList<CommonTag> commons1 = new ArrayList<CommonTag>();
		ArrayList<CommonTag> commons2 = new ArrayList<CommonTag>();
		for (LineString ln : geoms) {
			for (int i = 0 ; i < c ; i++) {
				LineString bigger = geoms[i];
				commons1.clear();
				commons2.clear();
				if (ln.getEnvelopeInternal().intersects(bigger.getEnvelopeInternal())){
					LCSSolver.lcs(ln.getCoordinates(), bigger.getCoordinates(), commons1, false);
					LCSSolver.lcs(bigger.getCoordinates(), ln.getCoordinates(), commons2, true);
				}
				
				//dbf.trees.add(LTreeNode.Init(ln, commons));
			}
			
			c++;
		}
		return null;
	}
}

class CoordsComp implements Comparator<LineString> {

	public int compare(LineString o1, LineString o2) {
		int n1 = o1.getNumPoints();
		int n2 = o2.getNumPoints();
		
		if (n1 > n2) {
			return -1;
		} else if (n1 < n2) {
			return 1;
		}
		return 0;
	}
}